package com.iwomy.envpro.platform.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iwomy.envpro.common.core.util.R;
import com.iwomy.envpro.common.excel.annotation.ResponseExcel;
import com.iwomy.envpro.platform.dto.AirRealTimeDataDTO;
import com.iwomy.envpro.platform.dto.HistoricalDataDTO;
import com.iwomy.envpro.platform.entity.DeviceLogEntity;
import com.iwomy.envpro.platform.service.HistoricalDataService;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 历史数据
 *
 * @author pig
 * @date 2023-08-31 09:28:08
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/historicalData")
@Tag(description = "historicalData", name = "历史数据")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class HistoricalDataController {

	private final HistoricalDataService historicalDataService;

	/**
	 * 获取指定所有条件数据
	 *
	 * @param historicalDataDTO
	 * @return
	 */
	@GetMapping("/list")
	public R list(@ParameterObject HistoricalDataDTO historicalDataDTO) {
		try {
			return R.ok(historicalDataService.list(historicalDataDTO));
		} catch (Exception e) {
			return R.failed(e.getMessage());
		}
	}

	/**
	 * 导出excel 表格
	 *
	 * @return excel 文件流
	 */
	@ResponseExcel
	@GetMapping("/export")
	public List<JSONObject> export(@ParameterObject HistoricalDataDTO historicalDataDTO) throws Exception {
		return historicalDataService.list(historicalDataDTO);

	}


}